import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'

import Components from 'unplugin-vue-components/vite';
import { VantResolver } from 'unplugin-vue-components/resolvers';

// import styleImport, { VantResolve } from 'vite-plugin-style-import';//TODO 待验证vant3配置值

// var postSssPxtorem = require('postcss-pxtorem')({
//   rootValue: 37.5,//基准值
//   propList: ['*'],
//   unitPrecision: 5//精准度，小数点后n位
// }) 

var postSssPxtoViewport = require('@jonny1994/postcss-px-to-viewport')({
  unitToConvert: 'px',//单位 px
  viewportWidth: 375,//竖屏宽度基准值
  unitPrecision: 5,//精准度，小数点后n位
  propList: ['*'],//白名单
  viewportUnit: 'vw',//运行后 转换结果单位
  fontViewportUnit: 'vw',//运行后 字体转换结果单位
  selectorBlackList: [],//黑名单
  minPixelValue: 1,
  mediaQuery: false,
  replace: true,
  exclude: undefined,
  include: undefined,
  landscape: false,
  landscapeUnit: 'vw',
  landscapeWidth: 568
}) 
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    Components({
      resolvers: [VantResolver()],
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  css: {
    postcss: {
      plugins: [
        // postSssPxtorem
        postSssPxtoViewport
      ]
    }
  }
})
